package com.qianli.cashmama.product.server.dao.impl;
import com.fqgj.common.api.Page;
import com.fqgj.common.base.AbstractBaseMapper;
import com.qianli.cashmama.product.server.dao.AppBusinessProductDao;
import com.qianli.cashmama.product.server.entity.AppBusinessProductEntity;
import org.springframework.stereotype.Repository;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
* User: frank
* Date: 2020-02-17
* Time: 16:17:58.268
*/

@Repository
public class AppBusinessProductDaoImpl extends AbstractBaseMapper<AppBusinessProductEntity> implements AppBusinessProductDao {

    @Override
    public List<AppBusinessProductEntity> getAppBusinessProductListByPosition(Integer position) {
        Map<String, Object> params = new HashMap<>();
        params.put("position", position);
        return getSqlSession().selectList(this.getStatement("getAppBusinessProductListByPosition"), params);
    }

    @Override
    public List<AppBusinessProductEntity> getAppBusinessProductListByPositionAndId(Integer position, Long businessProductId) {
        Map<String, Object> params = new HashMap<>();
        params.put("position", position);
        params.put("businessProductId", businessProductId);
        params.put("deleted", 0);
        return getSqlSession().selectList(this.getStatement("getAppBusinessProductListByPositionAndId"), params);
    }

    @Override
    public List<AppBusinessProductEntity> getAppBusinessProductListByPage(Map<String, Object> paramMap, Page page) {
        if(page != null){
            page.setTotalCount(this.queryAppBusinessProductCount(paramMap));
            paramMap.put("page", page);
        }
        return getSqlSession().selectList(this.getStatement("getAppBusinessProductListByPage"), paramMap);
    }

    @Override
    public Integer queryAppBusinessProductCount(Map<String, Object> paramMap) {
        return getSqlSession().selectOne(this.getStatement("queryAppBusinessProductCount"), paramMap);
    }

    @Override
    public List<AppBusinessProductEntity> getAppBusinessProductList(Map<String, Object> paramMap) {

        if (!paramMap.containsKey("deleted")) {
            paramMap.put("deleted", 0);
        }
        return getSqlSession().selectList(this.getStatement("selectByParams"), paramMap);
    }
}